package com.feng.demo.jakartacommons.mina;

import org.apache.log4j.Logger;
import org.apache.mina.core.service.IoHandler;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

public class ServerHandler implements IoHandler {
	private static Logger logger = Logger.getLogger(ServerHandler.class);
	public void sessionCreated(IoSession session) throws Exception {
		;// 会话创建
	}

	public void sessionOpened(IoSession session) throws Exception {
		;// 打开会话,与sessionCreated最大的区别是它是从另一个线程处调用的
	}

	public void sessionClosed(IoSession session) throws Exception {
		;// 会话结束，当连接关闭时被调用
	}

	public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
		;// 会话空闲
	}

	public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
		;// 异常捕获，Mina会自动关闭此连接
	}

	public void messageReceived(IoSession session, Object message) throws Exception {
		logger.info("RECV:"+message.toString());
		if(message.toString().contains("<stream:stream")){
			session.write("<bidi/>");
		}
		;// 接收到消息
	}

	public void messageSent(IoSession session, Object message) throws Exception {
		logger.info("");
		;// 发送消息
	}
}
